package com.ktg.mes.md.controller;

import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.core.page.TableDataInfo;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.mes.md.domain.MdStatistics;
import com.ktg.mes.md.domain.MdStatisticsBom;
import com.ktg.mes.md.service.IMdProductBomService;
import com.ktg.mes.md.service.IMdStatisticsBomService;
import com.ktg.mes.md.service.IMdStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 统计分类BOM关系Controller
 *
 * @author yinjinlu
 * @date 2022-05-09
 */
@RestController
@RequestMapping("/mes/md/statistical/bom")
public class MdStatisticalBomController extends BaseController
{
    @Autowired
    private IMdStatisticsBomService mdStatisticsBomService;

    @Autowired
    private IMdStatisticsService mdStatisticsService;

    /**
     * 查询统计分类BOM关系列表
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(MdStatisticsBom mdStatisticsBom)
    {
        startPage();
        List<MdStatisticsBom> list = mdStatisticsBomService.selectMdStatisticsBomList(mdStatisticsBom);
        return getDataTable(list);
    }

    /**
     * 查询统计分类BOM关系列表
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:list')")
    @GetMapping("/alllist")
    public TableDataInfo alllist(MdStatisticsBom mdStatisticsBom)
    {
        startPage();
        List<MdStatisticsBom> list = mdStatisticsBomService.selectMdStatisticsBomList(mdStatisticsBom);
        return getDataTable(list);
    }

    /**
     * 导出统计分类BOM关系列表
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:export')")
    @Log(title = "统计分类BOM关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdStatisticsBom mdStatisticsBom)
    {
        List<MdStatisticsBom> list = mdStatisticsBomService.selectMdStatisticsBomList(mdStatisticsBom);
        ExcelUtil<MdStatisticsBom> util = new ExcelUtil<MdStatisticsBom>(MdStatisticsBom.class);
        util.exportExcel(response, list, "统计分类BOM关系数据");
    }

    /**
     * 获取统计分类BOM关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:query')")
    @GetMapping(value = "/{bomId}")
    public AjaxResult getInfo(@PathVariable("bomId") Long bomId)
    {
        return AjaxResult.success(mdStatisticsBomService.selectMdStatisticsBomByBomId(bomId));
    }

    /**
     * 新增统计分类BOM关系
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:add')")
    @Log(title = "统计分类BOM关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdStatisticsBom mdStatisticsBom)
    {

        return toAjax(mdStatisticsBomService.insertMdStatisticsBom(mdStatisticsBom));
    }

    /**
     * 修改统计分类BOM关系
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:edit')")
    @Log(title = "统计分类BOM关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdStatisticsBom mdStatisticsBom)
    {
        return toAjax(mdStatisticsBomService.updateMdStatisticsBom(mdStatisticsBom));
    }

    /**
     * 删除统计分类BOM关系
     */
    @PreAuthorize("@ss.hasPermi('mes:md:statistical:bom:remove')")
    @Log(title = "统计分类BOM关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bomIds}")
    public AjaxResult remove(@PathVariable Long[] bomIds)
    {
        return toAjax(mdStatisticsBomService.deleteMdStatisticsBomByBomIds(bomIds));
    }
}
